<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            var longestConsecutive = function (nums) {
                if (!nums.length) return 0
                let set = new Set(nums)
                let res = 0
                for (let i = 0; i < nums.length; i++) {
                    if (set.has(nums[i] - 1)) {
                        continue
                    } else {
                        //找到了左边界
                        let temp = 1
                        let count = nums[i] + 1
                        while (set.has(count)) {
                            temp++
                            count++
                        }
                        res = Math.max(temp, res)
                    }
                }
                return res
            }
        </script>
    </body>
</html>
